package com.hao.main;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Một button trên footer
 * 
 * @author HaoDV
 * 
 */
public class FooterButton extends LinearLayout {

	// private static final int FOCUSED_TEXT_COLOR = 0xFFF0F0F0;
	private static final int NOMAL_TEXT_COLOR = 0xFFCCCCCC;

	private static Drawable focusedContentBkg;
	private static Drawable normalContentBkg;

	private GoogleMapActivity main;
	private TextView text;
	private ImageView icon;
	private LinearLayout content;

	public FooterButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		main = (GoogleMapActivity) context;
		inflate(context, R.layout.footer_button, this);

		focusedContentBkg = main.getResources().getDrawable(
				R.drawable.footer_btn_focused_bkg);
		normalContentBkg = main.getResources().getDrawable(
				R.drawable.footer_btn_normal_bkg);

		text = (TextView) findViewById(R.id.footer_button_content_text);
		icon = (ImageView)findViewById(R.id.footer_button_content_icon);
		content = (LinearLayout)findViewById(R.id.footer_content);
		setFooterFocus(false);
	}

	/**
	 * Thay đổi giao diện khi focus và không focus
	 * 
	 * @param isFocus
	 */
	public void setFooterFocus(boolean isFocus) {
		changeColor(isFocus);
		if (isFocus) {
			content.setBackgroundDrawable(focusedContentBkg);
			text.setTextColor(main.getResources().getColor(
					R.color.yellow_icon));
		} else {
			content.setBackgroundDrawable(normalContentBkg);
			text.setTextColor(NOMAL_TEXT_COLOR);
		}
		invalidate();
	}

	/**
	 * Đổi màu icon
	 * 
	 * @param isFocus
	 */
	private void changeColor(boolean isFocus) {
		switch (getId()) {
		case R.id.footer_back_btn:
			setIcon(R.drawable.back_icon);
			break;
		case R.id.footer_diretions_google_btn:
			if (isFocus) {
				setIcon(R.drawable.footer_map_icon_focus);
			} else {
				setIcon(R.drawable.footer_map_icon);
			}
			break;
		case R.id.footer_detail_from_map_btn:
			if (isFocus) {
				setIcon(R.drawable.footer_detail_icon_focus);
			} else {
				setIcon(R.drawable.footer_detail_icon);
			}
			break;
		default:
			break;
		}
	}
	
	public void setText(String textValue) {
		text.setText(textValue);
	}
	public void setIcon(int iconId) {
		icon.setImageDrawable(main.getResources().getDrawable(iconId));
	}
	
}
